<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="../tpl/header.html" /}
</head>
<body>
{include file="../tpl/menu.html" /}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" method="post" action="{:url('admin/admin/menuEdit')}">

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>上级菜单</label>
                <div class="layui-input-inline">
                    <select name="pid">
                        <option value="0">顶级菜单</option>
                        {volist name="list" id="vo"}
                        <option value="{$vo['id']}" {if condition="$data['pid'] eq $vo['id']"}selected="selected"{/if}>{$vo.mark}{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>上级菜单
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>菜单名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" value="{$data.name}" required="" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>展示的菜单名称,不要超过10个字符,支持特殊符号
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>是否是菜单</label>
                <div class="layui-input-block">
                    <input type="radio" value="0" name="is_menu" lay-skin="primary" title="否" {if condition="$data['is_menu'] eq 0"}checked="checked"{/if}>
                    <input type="radio" value="1" name="is_menu" lay-skin="primary" title="是" {if condition="$data['is_menu'] eq 1"}checked="checked"{/if}>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>排序号</label>
                <div class="layui-input-inline">
                    <input type="text" id="sort" value="{$data.sort}" required="" lay-verify="required" name="sort" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>排序号,系统安装升序排列,小的数字排在前面
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-inline">
                    <input type="text" id="icon" value="{$data.icon}" name="icon" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    展示图标,不填默认设置为系统默认的
                </div>
            </div>

            <div class="layui-form-item">
                <label for="url" class="layui-form-label">url</label>
                <div class="layui-input-inline">
                    <input type="text" id="url" value="{$data.url}" name="url" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    菜单的url地址,一般3级菜单才需要填写,不区分大小写,系统默认转换成小写
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">描述/帮助</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="desc" name="desc" class="layui-textarea">{$data.desc}</textarea>
                </div>
            </div>
            <input type="hidden" name="id" value="{$data.id}">
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">更新</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','layer','layedit'],
    function() {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer,layedit = layui.layedit;

        //编辑器部分
        layedit.set({
            uploadImage: {
                url: '{:url("admin/index/upload",["edit" => 1])}' //图片上传接口url
                ,type: 'post' //默认post
            }
        });
        var index = layedit.build('desc',{
            height: 350,
            tool: [
                'strong', //加粗
                'italic', //斜体
                'underline', //下划线
                'del', //删除线
                '|', //分割线
                'left', //左对齐
                'center', //居中对齐
                'right', //右对齐
                'link', //超链接
                'unlink', //清除链接
                'image', //插入图片
                'html',
                'code'//代码
            ]}); //建立编辑器,设置参数

        form.on('submit(add)', function(data) {
            //获取编辑器内容
            var content = layedit.getContent(index);
            data.field['desc'] = content;

            $.ajax({
                type:'post',
                data:data.field,
                dataType:'json',
                url:"{:url('admin/admin/menuEdit')}",
                success:function (e) {
                    if(e.code === 1){
                        layer.msg(e.msg, {icon: 6,time: layer_msg_success_time},
                            function() {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                    }else{
                        layer.msg(e.msg, {icon: 5,time: layer_msg_error_time});
                    }
                }
            });
            //发异步，把数据提交给php
            return false;
        });
    });
</script>
</body>
</html>